<?php

namespace app\common;

use think\Validate;

class DataValidate
{
    use InstanceTrait;

    //验证页数
    public function checkPager($data)
    {
        foreach ($data as $key => $value) {
            if (!is_array($value)) {
                $data[$key] = htmlentities($value);
            }
        }

        $rule = [
            "page_no" => "number|gt:0",
            "page_count" => "number",
        ];
        $msg = [
            "page_no.number" => "页码必须是数字",
            "page_no.gt" => "页码必须大于0",
            "page_count.number" => "每页数量必须是数字",
        ];

        $validate = Validate::make($rule, $msg);
        $result = $validate->check($data);

        if (!$result) {
            return ["code" => _MSG_INVALID_CLIENT_PARAM, "msg" => $validate->getError()];
        }
        return ["code" => _MSG_SYSTEM_SUCCESS, "msg" => "校验成功", "data" => $data];
    }
}
